package com.ruoyi.system.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.UserInterfaceInfo;
import com.ruoyi.system.mapper.UserInterfaceInfoMapper;
import com.ruoyi.system.service.IUserInterfaceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 用户调用接口关系Service业务层处理
 *
 * @author LinWei
 * @date 2023-04-10
 */
@Service
public class UserInterfaceInfoServiceImpl extends ServiceImpl<UserInterfaceInfoMapper, UserInterfaceInfo>
        implements IUserInterfaceInfoService {
    @Autowired
    private UserInterfaceInfoMapper userInterfaceInfoMapper;

    /**
     * 查询用户调用接口关系
     *
     * @param id 用户调用接口关系主键
     * @return 用户调用接口关系
     */
    @Override
    public UserInterfaceInfo selectUserInterfaceInfoById(Long id) {
        return userInterfaceInfoMapper.selectUserInterfaceInfoById(id);
    }

    /**
     * 查询用户调用接口关系列表
     *
     * @param userInterfaceInfo 用户调用接口关系
     * @return 用户调用接口关系
     */
    @Override
    public List<UserInterfaceInfo> selectUserInterfaceInfoList(UserInterfaceInfo userInterfaceInfo) {
        return userInterfaceInfoMapper.selectUserInterfaceInfoList(userInterfaceInfo);
    }

    /**
     * 新增用户调用接口关系
     *
     * @param userInterfaceInfo 用户调用接口关系
     * @return 结果
     */
    @Override
    public int insertUserInterfaceInfo(UserInterfaceInfo userInterfaceInfo) {
        userInterfaceInfo.setCreateTime(DateUtils.getNowDate());
        return userInterfaceInfoMapper.insertUserInterfaceInfo(userInterfaceInfo);
    }

    /**
     * 修改用户调用接口关系
     *
     * @param userInterfaceInfo 用户调用接口关系
     * @return 结果
     */
    @Override
    public int updateUserInterfaceInfo(UserInterfaceInfo userInterfaceInfo) {
        userInterfaceInfo.setUpdateTime(DateUtils.getNowDate());
        return userInterfaceInfoMapper.updateUserInterfaceInfo(userInterfaceInfo);
    }

    /**
     * 批量删除用户调用接口关系
     *
     * @param ids 需要删除的用户调用接口关系主键
     * @return 结果
     */
    @Override
    public int deleteUserInterfaceInfoByIds(Long[] ids) {
        return userInterfaceInfoMapper.deleteUserInterfaceInfoByIds(ids);
    }

    /**
     * 删除用户调用接口关系信息
     *
     * @param id 用户调用接口关系主键
     * @return 结果
     */
    @Override
    public int deleteUserInterfaceInfoById(Long id) {
        return userInterfaceInfoMapper.deleteUserInterfaceInfoById(id);
    }

    @Override
    public Boolean updateInterfaceInfoCount(Map<String, Object> params) {
        return userInterfaceInfoMapper.updateInterfaceInfoCount(params);
    }

    @Override
    public boolean invokeCount(long interfaceInfoId, long userId) {
        if (interfaceInfoId <= 0 || userId <= 0) {
            throw new ServiceException("参数异常");
        }
        Map<String,Object> params = new HashMap<>();
        params.put("userId" ,userId);
        params.put("interfaceInfoId",interfaceInfoId);
        Boolean aBoolean = this.updateInterfaceInfoCount(params);
        return aBoolean;
    }

}
